package com.tiny.diamond.internal.parser.json;

import com.tiny.diamond.*;
import com.tiny.diamond.internal.mapping.Converter;

/**
 * 单个JSON对象解释器。
 *
 * @author carver.gu
 * @since 1.0, Apr 11, 2010
 */
public class ObjectJsonParser<T extends DiamondResponse> implements DiamondParser<T> {

    private Class<T> clazz;

    public ObjectJsonParser(Class<T> clazz) {
        this.clazz = clazz;
    }

    @Override
    public T parse(String rsp) throws DiamondApiException {
        Converter converter = new JsonConverter();
        return converter.toResponse(rsp, clazz);
    }

    public Class<T> getResponseClass() {
        return clazz;
    }

    public SignItem getSignItem(DiamondRequest<?> request, String responseBody) throws DiamondApiException {
        Converter converter = new JsonConverter();
        return converter.getSignItem(request, responseBody);
    }

    public String encryptSourceData(DiamondRequest<?> request, String body, String format, String encryptType, String encryptKey, String charset) throws DiamondApiException {

        Converter converter = new JsonConverter();

        return converter.encryptSourceData(request, body, format, encryptType, encryptKey, charset);
    }


}
